package 测试案例;
import java.util.Scanner;

public  class Test2 {
    public static void main(String[] args) {

        int sum = StrToInt("adbc");
        System.out.println(sum);

    }


        public static int StrToInt(String str) {
            int n = str.length();
            if(n > 11 || n == 0){
                return 0;
            }
            int t = 0;//表示读取字符串的位置
            if(str.charAt(t) != '+' && str.charAt(t) != '-'){
                if(n == 11){
                    return 0;
                }else if(str.charAt(t) < '0' || str.charAt(t) > '9'){
                    return 0;
                }
            }
            int k = 1;
            if(str.charAt(t) < '0' || str.charAt(t) > '9'){
                if(str.charAt(t) == '-'){
                    k = -1;
                }
                t ++;
            }

            int sum = 0;

            while(t < n){
                if(str.charAt(t) < '0' || str.charAt(t) > '9'){
                    return 0;
                }
                sum *= 10;
                sum += str.charAt(t) - '0';
                t++;
            }

            return sum * k;
        }
}
